<?php

// 本类由系统自动生成，仅供测试用途
class IndexAction extends BaseAction {

    public function index() {
        $nowurl =  urlencode(get_url());
        redirect(U('User/Index'));
        print_r($_COOKIE);
    }

    public function ceshi() {
        $hangye = C("INDUSTRY");
        $res = D("industry")->select();
        foreach ($res as $key => $value) {
            $arr[$value['type']][$key]['name'] = $value['name'];
            $arr[$value['type']][$key]['id'] = $value['id'];
        }
        $this->assign('arr', $arr);
        $this->assign('hangye', $hangye);
        $this->display('test');
    }

    //营销页面
    public function market() {
//        $res = D('Order')->where("flag=" . C("PACKCLASSTYPE") . " and child_flag=" . C("INTERVIEWCLASS"))->select();
        //课程包可买数量如果小于等于0显示已售罄，
        $haowj_ustat = json_decode(MAGIC_QUOTES_GPC ? stripslashes(cookie('haowj_ustat')) : cookie('haowj_ustat'), true);
        import('@.Model.User.UserModel');
        $User = new UserModel();
        $this->userInfo = $User->checkLogin($haowj_ustat);
        $total = D("New_course")->where("p_type=" . C("PACKCLASSTYPE") . " and type=" . C("INTERVIEWCLASS"))->limit('1')->getField('limit_num');
        if ($total <= 0) {
            $flag = false;
        } else {
            $flag = true;
        }
        $seo['title']       = '好外教_面试英语,英语外教,英语口语学习,英语培训 ';
        $seo['keywords']    = '好外教,面试英语,英语外教,英语口语,英语培训,外教一对一,外企面试,面试口语';
        $seo['description'] = '金山好外教，致力于为英语学习者提供真人外教1对1英语口语培训的专业品牌.面试英语课程包,帮助求职者解决英语面试难题.更有英语面试现场模拟,修改英文简历等服务,更有效的帮助求职者攻克英语面试难题 ';
        $this->assign('seo',$seo);
        $this->assign('origin', $this->_get('origin'));
        $this->assign('channel', $this->_get('channel'));
        $this->assign('userInfo', $this->userInfo);
        $this->assign("flag", $flag);
        $this->display();
    }

    //营销评论提交
    public function pinglun() {

        //判断登录状态
        if (!cookie('haowj_ustat')) {
            $nowurl = urlencode(get_url());
            $href = C('WWWURL') . '/userlogin/index.htm?fromurl=' . C('APPURL') . '/Home/Index/market.html';
            echo json_encode(array('code' => 2, 'href' => $href));
        } else {
            $haowj_ustat = json_decode(MAGIC_QUOTES_GPC ? stripslashes(cookie('haowj_ustat')) : cookie('haowj_ustat'), true);
            import('@.Model.User.UserModel');
            $User = new UserModel();
            $this->userInfo = $User->checkLogin($haowj_ustat);
            $User = M("Review"); // 实例化User对象
            $data['user_id'] = $this->userInfo['id'];
            $data['content'] = $_POST['cont'];
            $data['create_time'] = time();
            $result = $User->add($data);
            if ($result) {
                echo json_encode(array('code' => 1, 'text' => '提交成功，客服将尽快给您回复'));
            } else {
                echo json_encode(array('code' => 0, 'text' => '评论失败'));
            }
        }
    }

    public function test() {
        $sid=$_POST['sid'];
        $chinal=$_POST['chinal'];
//        $nowurl = urlencode(get_url());
        if (!cookie('haowj_ustat')) {
            $this->ajaxReturn('', C('WWWURL') . '/userlogin/index.htm?origin='.$sid.'&channel='.$chinal.'&fromurl=' . C('APPURL') . '/Home/Index/market.html', 0);
        } else {
            $haowj_ustat = json_decode(MAGIC_QUOTES_GPC ? stripslashes(cookie('haowj_ustat')) : cookie('haowj_ustat'), true);
            import('@.Model.User.UserModel');
            $User = new UserModel();
            $this->userInfo = $User->checkLogin($haowj_ustat);
//            $res = D('Order')->where("flag=" . C("PACKCLASSTYPE") . " and child_flag=" . C("INTERVIEWCLASS"))->select();
            $total = D("New_course")->where("p_type=" . C("PACKCLASSTYPE") . " and type=" . C("INTERVIEWCLASS"))->limit('1')->select();
            $is_buy = D("Order")->where("user_id=" . $this->userInfo['id'] . ' and flag=' . C("PACKCLASSTYPE"))->find();
            $to = $total[0]['limit_num'];
            if(empty($is_buy))
            {
                    //添加一条订单记录，跳转到支付的页面
                    $total = D("New_course")->where("p_type=" . C("PACKCLASSTYPE") . " and type=" . C("INTERVIEWCLASS"))->limit('1')->find();
                    $order_no = order_id($this->userInfo['id']);
                    $User = M("Order"); // 实例化User对象
                    $data['user_id'] = $this->userInfo['id'];
                    $data['name'] = $total['name'];
                    $data['body'] = '购买' . $total['name'];
                    $data['money'] = $total['price'] * $total['discout'];
                    $data['course_id'] = $total['id'];
                    $data['cc_id'] = $this->userInfo['cc_id'];
                    $data['create_date'] = time();
                    $data['status'] = '0';
                    $data['flag'] = $total['p_type'];
                    $data['child_flag'] = $total['type'];
                    $data['order_no'] = $order_no;
                    $res = $User->add($data);
                    $this->ajaxReturn('', C("WWWURL") . '/usercenter/buy.htm?id=' . $res, '1');
            }
            if ($to <= 0) {
                $this->ajaxReturn('', '名额已经抢完了，不好意思了，等下回吧', '2');
            } else {
                if ($is_buy['status'] == 0) {
                    $this->ajaxReturn('', C("WWWURL") . '/usercenter/buy.htm?id=' . $is_buy['id'], '1');
                } elseif ($is_buy['status'] == 1) {
                    $this->ajaxReturn('', '一人只能限购一次', '3');
                } 
            }
        }
    }

    //现在没用到下面的方法
    public function test1() {
        $haowj_ustat = json_decode(cookie('haowj_ustat'), true);
        import('@.Model.User.UserModel');
        $User = new UserModel();
        $this->userInfo = $User->checkLogin($haowj_ustat);
        $user_id = 15536;
        $course_id = '';
        $total = D("New_course")->where("p_type=" . C("PACKCLASSTYPE") . " and type=" . C("INTERVIEWCLASS"))->limit('1')->find();
        $order_no = order_id($user_id);
        $User = M("Order"); // 实例化User对象
        $data['user_id'] = $user_id;
        $data['name'] = $total['name'];
        $data['body'] = '购买' . $total['name'];
        $data['money'] = $total['price'] * $total['discout'];
        $data['course_id'] = C("INTERVIEWCLASS");
        $data['cc_id'] = $this->userInfo['cc_id'];
        $data['create_date'] = time();
        $data['status'] = '0';
        $data['flag'] = $total['p_type'];
        $data['child_flag'] = $total['type'];
        $data['order_no'] = $order_no;
        $res = $User->add($data);
        $this->ajaxReturn('', '', '1');
    }

    public function video(){
        $this->display();
    }
    
    
    public function printHtml(){
        //下载显示的名字
        $user_id = $this->_get('id');
        $tid = $this->_get('tid');
        if($tid) $addsql = " and member_type=2 and teacher_id=".$tid;
        else $addsql = " and member_type=1 ";
        $result = D('Practice')->where("member_id=".$user_id.$addsql."  and practice_type=".C('PACKPRACTICE'))->select();
        if($result)
        {
            foreach ($result as $k=>$v)
            {
                $pct += $v['precentum'];
                $ret[$v['step']] = $v;
                $ret[$v['step']]['value'] = json_decode($v['value'],true);
                $ret[$v['step']]['count'] = count($ret[$v['step']]['value']);
            }
        }
        if(!$pct) $pct=0;
        $title = '我的简历_好外教网'; 
        $keywords = C('SEOKEYWORDS'); 
        $description = C('SEODESCRIPTION'); 
        $userInfo = D('User')->where("id=".$user_id)->find();
        $this->assign('userInfo',$userInfo);
        $seo['title']       = $title;
        $seo['keywords']    = $keywords;
        $seo['description'] = $description;
        $this->assign('seo',$seo);
        $this->assign('pct',$pct);
        $this->assign('pctsy',100-$pct);
        $this->assign('ret',$ret);
        $this->display();
    }
    
    public function center()
    {
        $trade = D('Trade')->select();
        $seo['title']       = '好外教 – 外教一对一 - 英语外教 - 英语口语学习 – 在线英语培训  ';
        $seo['keywords']    = '好外教,1对1外教,英语外教,英语口语,在线英语培训,外教一对一,商务英语培训';
        $seo['description'] = '好外教，致力于为英语学习者提供真人1对1外教在线英语口语培训的专业品牌。超过1000位全球顶尖外教，全部拥有TOSEL美国专业师资认证，专属顾问全程VIP服务，全天24小时，全球任意角落，随时随地和全球外教同步视频实时互动。 ';
        $this->assign('seo',$seo);
        $this->assign('trade',$trade);
        $this->display();
    }
}
